﻿
namespace GoldPrice.Windows.Forms
{
	/// <summary>
	/// abstract GoldPriceHtmlContent typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class GoldPriceHtmlContentDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<GoldPriceHtmlContentDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.GoldPriceHtmlContent _currentGoldPriceHtmlContent = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxGoldPriceHtmlContentDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxGoldPriceHtmlContentErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxGoldPriceHtmlContentBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the Id property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIdDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the HtmlContent property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxHtmlContentDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the PostedDate property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxPostedDateDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Url property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxUrlDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DomainName property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDomainNameDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the ViewCount property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxViewCountDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.GoldPriceHtmlContent> _GoldPriceHtmlContentList;
				
		/// <summary> 
		/// The list of GoldPriceHtmlContent to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.GoldPriceHtmlContent> GoldPriceHtmlContentList
		{
			get {return this._GoldPriceHtmlContentList;}
			set
			{
				this._GoldPriceHtmlContentList = value;
				this.uxGoldPriceHtmlContentBindingSource.DataSource = null;
				this.uxGoldPriceHtmlContentBindingSource.DataSource = value;
				this.uxGoldPriceHtmlContentDataGridView.DataSource = null;
				this.uxGoldPriceHtmlContentDataGridView.DataSource = this.uxGoldPriceHtmlContentBindingSource;				
				//this.uxGoldPriceHtmlContentBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxGoldPriceHtmlContentBindingSource_ListChanged);
				this.uxGoldPriceHtmlContentBindingSource.CurrentItemChanged += new System.EventHandler(OnGoldPriceHtmlContentBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnGoldPriceHtmlContentBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentGoldPriceHtmlContent = uxGoldPriceHtmlContentBindingSource.Current as Entities.GoldPriceHtmlContent;
			
			if (_currentGoldPriceHtmlContent != null)
			{
				_currentGoldPriceHtmlContent.Validate();
			}
			//_GoldPriceHtmlContent.Validate();
			OnCurrentEntityChanged();
		}

		//void uxGoldPriceHtmlContentBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <see cref="Entities.GoldPriceHtmlContent"/> instance.
		/// </summary>
		public Entities.GoldPriceHtmlContent SelectedGoldPriceHtmlContent
		{
			get {return this._currentGoldPriceHtmlContent;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxGoldPriceHtmlContentDataGridView.VirtualMode;}
			set
			{
				this.uxGoldPriceHtmlContentDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxGoldPriceHtmlContentDataGridView.AllowUserToAddRows;}
			set {this.uxGoldPriceHtmlContentDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxGoldPriceHtmlContentDataGridView.AllowUserToDeleteRows;}
			set {this.uxGoldPriceHtmlContentDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <see cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxGoldPriceHtmlContentDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxGoldPriceHtmlContentDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="GoldPriceHtmlContentDataGridViewBase"/> class.
		/// </summary>
		public GoldPriceHtmlContentDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxGoldPriceHtmlContentDataGridView = new System.Windows.Forms.DataGridView();
			this.uxGoldPriceHtmlContentBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxGoldPriceHtmlContentErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIdDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxHtmlContentDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxPostedDateDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxUrlDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDomainNameDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxViewCountDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxGoldPriceHtmlContentDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGoldPriceHtmlContentBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGoldPriceHtmlContentErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxGoldPriceHtmlContentErrorProvider
			// 
			this.uxGoldPriceHtmlContentErrorProvider.ContainerControl = this;
			this.uxGoldPriceHtmlContentErrorProvider.DataSource = this.uxGoldPriceHtmlContentBindingSource;						
			// 
			// uxGoldPriceHtmlContentDataGridView
			// 
			this.uxGoldPriceHtmlContentDataGridView.AutoGenerateColumns = false;
			this.uxGoldPriceHtmlContentDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxGoldPriceHtmlContentDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIdDataGridViewColumn,
		this.uxHtmlContentDataGridViewColumn,
		this.uxPostedDateDataGridViewColumn,
		this.uxUrlDataGridViewColumn,
		this.uxDomainNameDataGridViewColumn,
		this.uxViewCountDataGridViewColumn			});
			this.uxGoldPriceHtmlContentDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxGoldPriceHtmlContentDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxGoldPriceHtmlContentDataGridView.Name = "uxGoldPriceHtmlContentDataGridView";
			this.uxGoldPriceHtmlContentDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxGoldPriceHtmlContentDataGridView.TabIndex = 0;	
			this.uxGoldPriceHtmlContentDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxGoldPriceHtmlContentDataGridView.EnableHeadersVisualStyles = false;
			this.uxGoldPriceHtmlContentDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnGoldPriceHtmlContentDataGridViewDataError);
			this.uxGoldPriceHtmlContentDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnGoldPriceHtmlContentDataGridViewCellValueNeeded);
			this.uxGoldPriceHtmlContentDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnGoldPriceHtmlContentDataGridViewCellValuePushed);
			
			//
			// uxIdDataGridViewColumn
			//
			this.uxIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIdDataGridViewColumn.DataPropertyName = "Id";
			this.uxIdDataGridViewColumn.HeaderText = "Id";
			this.uxIdDataGridViewColumn.Name = "uxIdDataGridViewColumn";
			this.uxIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIdDataGridViewColumn.ReadOnly = false;		
			//
			// uxHtmlContentDataGridViewColumn
			//
			this.uxHtmlContentDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxHtmlContentDataGridViewColumn.DataPropertyName = "HtmlContent";
			this.uxHtmlContentDataGridViewColumn.HeaderText = "HtmlContent";
			this.uxHtmlContentDataGridViewColumn.Name = "uxHtmlContentDataGridViewColumn";
			this.uxHtmlContentDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxHtmlContentDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxHtmlContentDataGridViewColumn.ReadOnly = false;		
			//
			// uxPostedDateDataGridViewColumn
			//
			this.uxPostedDateDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxPostedDateDataGridViewColumn.DataPropertyName = "PostedDate";
			this.uxPostedDateDataGridViewColumn.HeaderText = "PostedDate";
			this.uxPostedDateDataGridViewColumn.Name = "uxPostedDateDataGridViewColumn";
			this.uxPostedDateDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxPostedDateDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxPostedDateDataGridViewColumn.ReadOnly = false;		
			//
			// uxUrlDataGridViewColumn
			//
			this.uxUrlDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxUrlDataGridViewColumn.DataPropertyName = "Url";
			this.uxUrlDataGridViewColumn.HeaderText = "Url";
			this.uxUrlDataGridViewColumn.Name = "uxUrlDataGridViewColumn";
			this.uxUrlDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxUrlDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxUrlDataGridViewColumn.ReadOnly = false;		
			//
			// uxDomainNameDataGridViewColumn
			//
			this.uxDomainNameDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDomainNameDataGridViewColumn.DataPropertyName = "DomainName";
			this.uxDomainNameDataGridViewColumn.HeaderText = "DomainName";
			this.uxDomainNameDataGridViewColumn.Name = "uxDomainNameDataGridViewColumn";
			this.uxDomainNameDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDomainNameDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDomainNameDataGridViewColumn.ReadOnly = false;		
			//
			// uxViewCountDataGridViewColumn
			//
			this.uxViewCountDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxViewCountDataGridViewColumn.DataPropertyName = "ViewCount";
			this.uxViewCountDataGridViewColumn.HeaderText = "ViewCount";
			this.uxViewCountDataGridViewColumn.Name = "uxViewCountDataGridViewColumn";
			this.uxViewCountDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxViewCountDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxViewCountDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxGoldPriceHtmlContentDataGridView);
			this.Name = "GoldPriceHtmlContentDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxGoldPriceHtmlContentErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGoldPriceHtmlContentDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGoldPriceHtmlContentBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				GoldPriceHtmlContentDataGridViewEventArgs args = new GoldPriceHtmlContentDataGridViewEventArgs();
				args.GoldPriceHtmlContent = _currentGoldPriceHtmlContent;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class GoldPriceHtmlContentDataGridViewEventArgs : System.EventArgs
		{
			private Entities.GoldPriceHtmlContent	_GoldPriceHtmlContent;
	
			/// <summary>
			/// the  Entities.GoldPriceHtmlContent instance.
			/// </summary>
			public Entities.GoldPriceHtmlContent GoldPriceHtmlContent
			{
				get { return _GoldPriceHtmlContent; }
				set { _GoldPriceHtmlContent = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxGoldPriceHtmlContentDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnGoldPriceHtmlContentDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxGoldPriceHtmlContentDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnGoldPriceHtmlContentDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxGoldPriceHtmlContentDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIdDataGridViewColumn":
						e.Value = GoldPriceHtmlContentList[e.RowIndex].Id;
						break;
					case "uxHtmlContentDataGridViewColumn":
						e.Value = GoldPriceHtmlContentList[e.RowIndex].HtmlContent;
						break;
					case "uxPostedDateDataGridViewColumn":
						e.Value = GoldPriceHtmlContentList[e.RowIndex].PostedDate;
						break;
					case "uxUrlDataGridViewColumn":
						e.Value = GoldPriceHtmlContentList[e.RowIndex].Url;
						break;
					case "uxDomainNameDataGridViewColumn":
						e.Value = GoldPriceHtmlContentList[e.RowIndex].DomainName;
						break;
					case "uxViewCountDataGridViewColumn":
						e.Value = GoldPriceHtmlContentList[e.RowIndex].ViewCount;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxGoldPriceHtmlContentDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnGoldPriceHtmlContentDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxGoldPriceHtmlContentDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIdDataGridViewColumn":
						GoldPriceHtmlContentList[e.RowIndex].Id = (System.Int32)e.Value;
						break;
					case "uxHtmlContentDataGridViewColumn":
						GoldPriceHtmlContentList[e.RowIndex].HtmlContent = (System.String)e.Value;
						break;
					case "uxPostedDateDataGridViewColumn":
						GoldPriceHtmlContentList[e.RowIndex].PostedDate = (System.DateTime?)e.Value;
						break;
					case "uxUrlDataGridViewColumn":
						GoldPriceHtmlContentList[e.RowIndex].Url = (System.String)e.Value;
						break;
					case "uxDomainNameDataGridViewColumn":
						GoldPriceHtmlContentList[e.RowIndex].DomainName = (System.String)e.Value;
						break;
					case "uxViewCountDataGridViewColumn":
						GoldPriceHtmlContentList[e.RowIndex].ViewCount = (System.Int32?)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
